/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.notaria.guerrasalas.bc;

import gob.satt.comun.jpa.Command;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author Administrator
 */
public class ListarAniosCommand implements Command<List<Integer>> {

    public ListarAniosCommand() {
    }

    @Override
    public List<Integer> execute(EntityManager em) throws Exception {
        List<Integer> lista = null;
        List<Object> listaAux = null;
        listaAux = em.createNativeQuery("SELECT DISTINCT(ANIO) FROM TICKET ORDER BY ANIO DESC")
                .getResultList();
        if (listaAux != null) {
            for (Object obj : listaAux) {
                if (lista == null) {
                    lista = new ArrayList<Integer>();
                }
                lista.add(Integer.parseInt(obj.toString().substring(1, obj.toString().length() - 1)));
            }
        }
        return lista;
    }
}
